using System;

using DbSharper.Library.Caching;
using DbSharper.Library.Data;
using DbSharper.Library.Model;

using DbSharper.Core.Enums;
using DbSharper.Core.Models;
using DbSharper.Core.Models.Core;
using DbSharper.Core.Models.Dbo;

namespace DbSharper.Core.DataAccess.Core
{
	#region Produt

	/// <summary>
	/// Data access methods of Produt.
	/// </summary>
	public static partial class Produt
	{
		#region Cache keys of methods.
		
		/// <summary>
		/// Cache key of method GetList.
		/// </summary>
		public const string Produt_GetList = "Core.Core.Produt.GetList";
		
		#endregion

		#region Method GetList
		/// <summary>
		/// Invoked after executed method GetList.
		/// </summary>
		static partial void After_GetList(ProdutCollection result);

		/// <summary>
		/// Summary of GetList.
		/// </summary>
		public static ProdutCollection GetList()
		{
			return GetList(ConnectionStrings.Core);
		}

		/// <summary>
		/// Summary of GetList.
		/// </summary>
		public static ProdutCollection GetList(string connectionString)
		{
			CachingService cache = new CachingService(Produt_GetList);

			ProdutCollection result = cache.Get() as ProdutCollection;

			if (result == null)
			{
				result = new ProdutCollection();

				using (global::System.Data.SqlClient.SqlDataReader reader = SqlHelper.ExecuteReader(connectionString, global::System.Data.CommandType.StoredProcedure, "[Core].[Produt_GetList]"))
				{
					result = new ProdutCollection();
					
					while (reader.Read())
					{
						result.Add(new ProdutItem(reader));
					}
				}
				
				After_GetList(result as ProdutCollection);

				cache.Insert(result);
			}
			
			return result;
		}
		
		/// <summary>
		/// Remove cache of method GetList.
		/// </summary>
		public static void Remove_GetList()
		{
			CachingService cache = new CachingService(Produt_GetList);
			
			cache.Remove();
		}
		
		#endregion
	}

	#endregion
}
